package week6;

import java.math.BigInteger;

public class Ex56 {
    public static void main(String[] args) {
        int ans = 0, sum;
        BigInteger a, b;
        char[] arr;
        for (int i = 2; i < 100; ++i){
            a = BigInteger.valueOf(i);
            for (int j = 1; j < 100; ++j){
                b = a.pow(j);
                arr = b.toString().toCharArray();
                sum = 0;
                for (char c : arr){
                    sum += c - '0';
                }
                if (sum > ans)
                    ans = sum;
            }
        }
        System.out.println(ans);
    }
}
